<!--
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-12-04 16:07:30
 * @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime: 2025-04-18 00:32:07
 * @FilePath: /vue-element-admin/src/views/storeSetup/cineraryUrn/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">
    <!-- 搜索区 -->

    <div class="filter-container">
      <el-form :inline="true" :model="listQuery" class="demo-form-inline">
        <!-- <el-form-item label="收支情况">
          <el-select
            v-model="listQuery.type"
            placeholder="收支情况"
            clearable
            class="filter-item"
          >
            <el-option
              v-for="item in typeDatas"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </el-form-item> -->
        <el-form-item label="操作用户">
          <el-input
            v-model="listQuery.price"
            placeholder=""
            class="filter-item"
            @keyup.enter.native="handleFilter"
          />
        </el-form-item>

        <!-- <el-form-item label="开始日期">
          <el-date-picker
            v-model="listQuery.startDate"
            type="date"
            placeholder="选择开始日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期">
          <el-date-picker
            v-model="listQuery.endDate"
            type="date"
            placeholder="选择结束日期"
            value-format="yyyy-MM-dd 23:59:59"
          >
          </el-date-picker>
        </el-form-item> -->
      </el-form>

      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <!-- <el-button
        class="filter-item"
        style="margin-left: 10px"
        type="primary"
        icon="el-icon-edit"
        @click="handleCreate"
      >
        新增
      </el-button> -->
      <el-button
        :loading="downloadLoading"
        class="filter-item"
        type="primary"
        icon="el-icon-download"
        @click="handleDownload"
      >
        导出
      </el-button>
    </div>
    <el-table empty-text='暂无数据' :data="tableList" style="width: 100%; margin-top: 30px" border>
      <el-table-column align="center" label="操作用户" width="220">
        <template slot-scope="scope">
          {{ scope.row.type }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="交易金额" width="220">
        <template slot-scope="scope">
          {{ scope.row.price }}
        </template>
      </el-table-column>

      
      <el-table-column align="center" label="交易时间" width="220">
        <template slot-scope="scope">
          {{ scope.row.createTime }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="内容" width="220">
        <template slot-scope="scope">
          {{ scope.row.remark }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="余额" width="220">
        <template slot-scope="scope">
          {{ scope.row.money }}
        </template>
      </el-table-column>
      <!-- <el-table-column align="header-center" label="Description">
        <template slot-scope="scope">
          {{ scope.row.price }}
        </template>
      </el-table-column> -->
      <!-- <el-table-column
        label="Actions"
        align="center"
        width="230"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row, $index }">
          <el-button
          size="mini"
          type="danger"
          @click="handleVoid(row, $index)"
        >
          作废
        </el-button>
        <el-button
        v-if="userInfo.isShopLeader!==0"
        size="mini"
        type="danger"
        @click="handleRecover(row, $index)"
      >
        恢复
      </el-button>
        
        </template>
      </el-table-column> -->
    </el-table>

    <!-- 分页区 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.pageNum"
      :limit.sync="listQuery.limit"
      @pagination="getListQuery"
    />

    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form
        ref="dataForm"
        :model="temp"
        label-width="120px"
        label-position="right"
        class="demo-form-inline"
        :inline="true"
      >
      <el-form-item label="物料名称">
        <el-input
          v-model="temp.name"
          :autosize="{ minRows: 2, maxRows: 4 }"
          placeholder="物料名称"
        />
      </el-form-item>
          <el-form-item label="类型" >
            <el-select
              v-model="temp.type"
              class="filter-item"
              placeholder="类型"
            >
              <el-option
                v-for="item in typeDatas"
                :key="item"
                :label="item"
                :value="item"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="规格">
          <el-select
          v-model="temp.specification"
          class="filter-item"
          placeholder="规格"
        >
          <el-option
            v-for="item in specification"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
        </el-form-item>
        <el-form-item label="单价">
          <el-input
            v-model="temp.price"
            :autosize="{ minRows: 2, maxRows: 4 }"
            placeholder="物料名称"
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="temp.name"
            :autosize="{ minRows: 2, maxRows: 4 }"
            placeholder="备注"
          />
        </el-form-item>
      
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消 </el-button>
        <el-button
          type="primary"
          @click="dialogStatus === 'create' ? createData() : updateData()"
        >
         确认
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import path from "path";
import { deepClone } from "@/utils";
import { getListQuery, create, update, deleteData } from "@/api/financialManagement";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import { mapState } from "vuex";

export default {
  components: { Pagination },

  data() {
    return {
      typeDatas:["低值易耗","固定资产","货品号"],
      specification:['个','袋','包','盒','件','张','瓶','箱'],
      tableList: [],
      listQuery: {
        pageNum: 1,
        pageSize: 20,
      },
      checkStrictly: false,

      defaultProps: {
        children: "children",
        label: "name",
      },
      total: 0,
      listLoading: true,
      temp: {
        type: "",
        price: "",
        name: "",
      },
      downloadLoading: false,
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        update: "编辑",
        create: "新增",
      },
      productDatas: [],
      // checkProductDatas:[],
    };
  },
  computed: {
    ...mapState({
      userInfo: state => state.user.userInfo,
    }),
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    }
  },
  mounted(){
    console.log(444,this.userInfo)
  },
  created() {
    this.getListQuery();
    // this.getProductDatas();
  },

  methods: {
    // async getProductDatas() {
    //   getList().then((response) => {
    //     this.productDatas = response.data;
    //   });
    // },
    handleVoid(row){

    },
    handleRecover(row){

},
    handleUpdate(row) {
      this.temp = Object.assign({}, row); // copy obj
      this.temp.timestamp = new Date(this.temp.timestamp);
      this.dialogStatus = "update";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleDelete(row, index) {
      deleteData(row.id).then((response) => {
        this.listLoading = true;
        setTimeout(() => {
          this.listLoading = false;
        }, 1.5 * 1000);
        this.getListQuery();
      });
    },
    updateData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.listLoading = true;
          const tempData = Object.assign({}, this.temp);
          tempData.timestamp = +new Date(tempData.timestamp); // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
          update(tempData).then(() => {
            // this.list.splice(index, 1, this.temp);
            this.dialogFormVisible = false;
            this.$notify({
              title: "Success",
              message: "Update Successfully",
              type: "success",
              duration: 2000,
            });
            this.listLoading = false;
            this.getListQuery();
          });
        }
      });
    },
    createData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          create(this.temp).then(() => {
            this.dialogFormVisible = false;
            this.$notify({
              title: "Success",
              message: "Created Successfully",
              type: "success",
              duration: 2000,
            });
            this.getListQuery();
          });
        }
      });
    },
    resetTemp() {
      this.temp = {
        type: "",
        price: "",
        name: "",
      };
    },
    handleCreate() {
      this.resetTemp();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    getListQuery() {
      this.listLoading = true;
      getListQuery(this.listQuery).then((response) => {
//        response.data.records.map((item)=>{
//           // item.productList=JSON.parse(item.productList) 
// // console.log(888, JSON.parse(item.productList) ,item.productList)

//           // return item
//         })
        this.tableList = response.data.records;

        this.total = response.data.total;
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false;
        }, 1.5 * 1000);
      });
    },
    handleFilter() {
      this.listQuery.pageNum = 1;
      this.getListQuery();
    },
    handleAdd() {},
    formatJson(filterVal) {
      return this.tableList.map((v) =>
        filterVal.map((j) => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
    handleDownload() {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = ["内容", "金额", "创建时间", "备注"];
        const filterVal = ["name", "price", "createTime", "remark"];
        const data = this.formatJson(filterVal);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "table-list",
        });
        this.downloadLoading = false;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  .roles-table {
    margin-top: 30px;
  }
  .permission-tree {
    margin-bottom: 30px;
  }
}
</style>
